// 深拷贝
function deepClone(target) {

    let newData

    if (typeof target === 'object') {
        if (Array.isArray(target)) {
            newData = []
            for (let i in target) {
                newData.push(deepClone(target[i]))
            }
        } else if (target == null) {
            newData = null
        } else if (target instanceof RegExp) {
            newData = target
        } else {
            newData = {}
            for (let i in target) {
                newData[i] = deepClone(target[i])
            }
        }


    } else {
        newData = target
    }
    return newData
}


// 防抖   Array.prototype.shift.call(arguments)
function debounce(fn, delay) {
    let timer
    return function () {
        if (timer) clearTimeout(timer)
        timer = setTimeout(function () {
            fn.apply(this, arguments)
        }, delay)
    }
}

// 节流 
function throttle(fn, delay) {
    let flag = true

    return function () {
        if (!flag) return
        flag = false
        setTimeout(function () {
            fn.apply(arguments)
            flag = true
        }, delay)
    }
}

// 数组去重
function quchong1(arr) {
    return Array.from(new Set(arr))
}
function quchong2(arr) {
    arr.filter((item,index,arr) =>{
        return arr.indexOf(item,0) === index 
    })


}

function quchong3(arr) {
    let map = new Map()
    let newArr = []
    arr.map(item =>{
        if(!map.has(item)) {
            map.set(item,item)
            newArr.push(item)
        }
    })

    return newArr
}


function quchong4(arr) {
    let len = arr.length
    for(let i = 0;i<len;i++) {
        for(let j = i+1;j<len;j++) {
            if(arr[i]===arr[j]) {
                arr.splice(j,1)
                j--
                len--
            }
        }
    }
}

function quchong5(arr) {
    let newArr = []
    arr.map(item =>{
        if(newArr.indexOf(item)===-1) {
            newArr.push(item)
        }
    })

    return newArr
}